import os

from UI.TableSet import Ui_TableSet
from Class.VoltSignal import dataBase
from Class.Devices import *
from importQT import *

class UITableSet(QDialog, Ui_TableSet):
    def __init__(self):
        super(UITableSet, self).__init__()
        self.setupUi(self)
        self.setWindowFlags(Qt.WindowCloseButtonHint)
        self.setFixedSize(self.width(), self.height())
        self.setAttribute(Qt.WA_DeleteOnClose)
        self.applyResource()
        self.chks = []
        # self.layout().removeItem(self.verticalLayout)
        # self.gridLayout = QtWidgets.QGridLayout(self)
        # self.layout().addLayout(self.gridLayout)
        for i, name in enumerate(dataBase.dbColNames):
            if name == dataBase.dbColUser[0] and deviceType == "CS":
                continue
            chk = QCheckBox(self)
            chk.setText(name)
            if i in device.getresultcolHidden():
                chk.setChecked(False)
            else:
                chk.setChecked(True)
            # self.gridLayout.addWidget(chk, i/2, i%2, 1, 1)
            self.verticalLayout.addWidget(chk)
            self.chks.append(chk)


    def applyResource(self):
        self.setWindowIcon(getIcon())

    def closeEvent(self, event):
        device.getresultcolHidden().clear()
        for i, chk in enumerate(self.chks):
            if chk.checkState() == Qt.Unchecked:
                device.getresultcolHidden().append(i)


